package com.wuxiaoqin.server.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;

import com.wuxiaoqin.server.entity.Address;
import com.wuxiaoqin.server.entity.Commodity;
import com.wuxiaoqin.server.service.ICommodityService;
import com.wuxiaoqin.server.service.SearchService;
import com.wuxiaoqin.server.service.impl.AddressServiceImpl;
import com.wuxiaoqin.server.vo.GoodsVo;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.math.BigDecimal;
import java.util.List;

@CrossOrigin
@RestController
@RequestMapping("index")
public class IndexController {

    @Autowired
    private ICommodityService commodityService;

    @Autowired
    private SearchService searchService;
    @ApiOperation(value = "首页热销商品")
    @GetMapping("/goodsBySale/{number}")
    public List<Commodity> goodsBySale(@PathVariable("number") Integer number){

        return commodityService.goodsBySale(number);
    }

    @ApiOperation(value = "首页最新商品")
    @GetMapping("/getHotGood/{fristmenu}/{number}")
    public List<Commodity> getHotGood(@PathVariable("fristmenu") Integer fristmenu,
                                @PathVariable("number") Integer number){
        return commodityService.getHotGood(fristmenu,number);
    }
    @ApiOperation("分页所有商品")
    @GetMapping("/getAllGoods")
    public Page<Commodity> getAllGoods(@RequestParam(value = "pn",defaultValue = "1") Integer pn,
                                       @RequestParam(value = "size",defaultValue = "8") Integer size){
        return commodityService.getAllGoods(pn,size);
    }


    @ApiOperation("搜索框加价格")
    @GetMapping("/exploreGoods")
    public Page<GoodsVo> exploreGoods(@RequestParam(value = "pn",defaultValue = "1") Integer pn,
                                        @RequestParam(value = "size",defaultValue = "8") Integer size,
                                        @RequestParam(value = "maxPrice",defaultValue = "9999999999") BigDecimal maxPrice,
                                        @RequestParam(value = "minPrice",defaultValue ="0") BigDecimal minPrice,
                                        @RequestParam(value = "keyStr",required = false) String searchStr
                                        ){
        return searchService.selectByCondition(pn,size,maxPrice,minPrice,searchStr);
    }
    @ApiOperation("分类加价格")
    @GetMapping("/exploreClassGoods")
    public Page<Commodity> exploreClassGoods(@RequestParam(value = "pn",defaultValue = "1") Integer pn,
                                      @RequestParam(value = "size",defaultValue = "8") Integer size,
                                      @RequestParam(value = "firstClass") Integer firstClass,
                                      @RequestParam(value = "secondClass") Integer secondClass,
                                      @RequestParam(value = "maxPrice",defaultValue = "9999999999") BigDecimal maxPrice,
                                      @RequestParam(value = "minPrice",defaultValue ="0") BigDecimal minPrice ){
        return commodityService.exploreClassGoods(pn,size,firstClass,secondClass,maxPrice,minPrice);
    }


    @ApiOperation("搜索框")
    @GetMapping("/search")
    public Page<GoodsVo> search(@RequestParam(value = "keyStr") String searchStr,
                                @RequestParam(value = "pn") Integer pageNum,
                                @RequestParam(value = "size") Integer pageSize
    ){
        return searchService.doSearch(searchStr,pageNum,pageSize);
    }

    @Autowired
    private AddressServiceImpl addressService;
    @ApiOperation("测试")
    @GetMapping("/aaa")
    public Address aaa(){

        return  addressService.selectddd();

    }
}
